package com.extremelylargepackage.entity;


import com.extremelylargepackage.GameResources;
import com.extremelylargepackage.sprite.AbstractSprite;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;

public class ScrollingBackground extends Entity
{
	private boolean _scrolling = true;
	
	public ScrollingBackground(AbstractSprite image)
	{
		super();
		_sprite = image;
	}

	public void updateState(long time)
	{
		if(_scrolling)
		{
			_locY += (_dirY * time) / 1000f;
			if(_locY >= _sprite.getHeight())
				_locY = 0;
		}
	}
	
	public void setScrolling(boolean scrolling)
	{
		_scrolling = scrolling;
	}
	
	@Override
	public void draw(Canvas c)
	{
		//Tile the image across the screen.
		int yStart = (int) _locY;
		while(yStart > 0)
			yStart -= _sprite.getHeight();
		for(int x = 0; x < GameResources.SCREEN_WIDTH; x += _sprite.getWidth())
		{
			for(int y = yStart; y < GameResources.SCREEN_HEIGHT; y += _sprite.getHeight())
			{
				c.drawBitmap(_sprite.getBitmap(), x, y, null);
			}
		}
	}
	
	@Override
	public void onCollision(Entity z) 
	{
		//do nothing
	}

}
